iPhone SDK - (void)viewDidLoad { } - Show Progress

Posted by Hank Brekke on Stack Overflow See other posts from Stack Overflow or by Hank Brekke
Published on 2010-03-18T18:06:07Z Indexed on 2010/03/18 18:11 UTC
Read the original article Hit count: 565

I have a long - (void)viewDidLoad { } function that uses the internet to load a page, and whenever the application loads the URL, the screen is black. I have a UIActivityIndicator setup to show that the address is loading, but I don't know how to prevent it from seeming as if the application is not responding, and I don't want to show the network activity indicator [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; because the screen will still be black, just with a loader in the top corner. My code is below:

- (void)viewDidLoad {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    email.text = [defaults objectForKey:@"mom_email"];
    pass.text = [defaults objectForKey:@"mom_pass"];
    if (email.text != nil && pass.text != nil) {
        [self login:loginBtn];
    }
}
- (IBAction)login:(id)sender {
    [email resignFirstResponder];
    [pass resignFirstResponder];
    [loader startAnimating]; // Does nothing though
    NSString *em = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)email.text,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
    NSString *ps = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)pass.text,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
    NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:@"localhost" path:[[NSString alloc] initWithFormat:@"/app/login.php?email=%@&pass=%@", em, ps]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *loginResult = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    [loader stopAnimating];
    NSRange range = [loginResult rangeOfString:@"1"];
    if (range.location != NSNotFound) {
        [self dismissModalViewControllerAnimated:YES]; // Doesn't do anything if function called from viewDidLoad
    }
}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk-3.1.2